package com.qinghe.pro.controller.main;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qinghe.pro.entity.main.User;
import com.qinghe.pro.service.main.UserService;
import com.qinghe.pro.shiro.ShiroUser;
import com.qinghe.utils.AjaxObject;
import com.qinghe.utils.SecurityUtils;

@Controller
@RequestMapping("/manager/user")
public class UserController {

	@Autowired
	@Qualifier("userServiceImpl")
	private UserService userService;

	private static final String UPDATE = "manager/update";

	/**
	 * 进入个人资料页面
	 */
	@RequestMapping(value = "/update", method = RequestMethod.GET)
	public String preUpdate(Map<String, Object> map) {
		ShiroUser shiroUser = SecurityUtils.getShiroUser();
		
		map.put("user", shiroUser.getUser());
		return UPDATE;
	}

	/**
	 * 修改个人资料
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public @ResponseBody AjaxObject update(User user) {
		userService.update(user);

		return AjaxObject.newOk("修改资料成功！");
	}

}
